package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;

	[SWF(width=955,height=410)]
	public class ColorGradient extends Sprite
	{
		public var bmp:Bitmap;
		public var bmd:BitmapData;
		
		public function ColorGradient()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			bmd = new BitmapData(955,220,false,0);
			bmp = new Bitmap(bmd);
			addChild(bmp);
			
			var i:int=0;
			var j:int=0;
			for(i=0; i<955; i++)
			{
				for(j=0; j<220; j++)
				{
					drawPixel(i, j, 0,0,0);
				}
			}
//			trace(hx,hy);
		}
		
		private var FOV:Number = 120;
		private var a1:Number = Math.cos(Math.PI*21/180);
		private var a2:Number = Math.sin(Math.PI*21/180);
		
		private var hx:Number=0;//263;
		private var hy:Number=0;//237;
		
		protected function drawPixel(x:int, y:int, red:int, green:int, blue:int):void
		{
			var dx:Number = x-477;
			var dy:Number = a1*y;
			var dz:Number = a2*y+FOV;
			
			var _x:Number = x-477 - dx*FOV/dz;
			var _y:Number = y - dy*FOV/dz;
			
			if(hx < _x) hx = _x;
			if(hy < _y) hy = _y;
			
			red = 128 + 128*(_y/96);
			green = 128;
			blue = 128 + 128*(_x/189);
			
			var color:uint = (red << 16)+(green << 8)+blue;
			bmd.setPixel(x, 220-y, color);
		}
	}
}